package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.domain.DynamicCommentInfo;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xuanqicheng
 * @create 2019-21-13:06
 */
@Repository
public class DynamicCommentInfoDao {

    @Autowired
    private SqlSession sqlSession;

    public void addDynamicComment(DynamicCommentInfo dynamicCommentInfo) {
        sqlSession.insert("addDynamicComment",dynamicCommentInfo);
    }

    public List<DynamicCommentInfo> selectDynamicCommentInfoByDynamicId(Long dynamicId) {
        return sqlSession.selectList("selectDynamicCommentInfoByDynamicId",dynamicId);
    }

    public DynamicCommentInfo getDynamciCommentById(long id) {
        return sqlSession.selectOne("getDynamciCommentById",id);
    }

    public List<DynamicCommentInfo> getDynamicCommentPageByDynamicId(long dynamicId, int startNum, int pageSize) {
        Map<String,Object> map = new HashMap<>();
        map.put("dynamicId",dynamicId);
        map.put("startNum",startNum);
        map.put("pageSize",pageSize);
        return sqlSession.selectList("getDynamicCommentPageByDynamicId",map);
    }

    public int getDynamicCommentCountByDynamicId(long dynamicId) {
        return sqlSession.selectOne("getDynamicCommentCountByDynamicId",dynamicId);
    }
}
